package com.hdq.structure.array;

import java.util.Arrays;

public class ArrayTest {
	//简单的二分法查找
	public String findItem(int[] a,int kw){
		int lowerIndx = 0;
		int highIndex = a.length-1;
		int middleIndex ;
		while(true){
			System.out.println("查找范围："+lowerIndx+"~"+highIndex);
			middleIndex = (lowerIndx+highIndex)/2;
			if(a[middleIndex]==kw){
				System.out.println("find it : "+ kw);
				break;
			}else if(a[middleIndex]<kw){
				lowerIndx = middleIndex+1;
			}else if(a[middleIndex]>kw){
				highIndex = middleIndex-1;
			}
		}
		return "ok";
	}
	public static void main(String[] args) {
			int[] ars = new int[11];
			ars[0]=1;
			ars[1]=2;
			ars[2]=3;
			ars[3]=4;
			ars[4]=5;
			ars[5]=6;
			ars[6]=7;
			ars[7]=8;
			ars[8]=9;
			ars[9]=10;
			ars[10]=11;
			System.out.println(ars[3]);
			ArrayTest aTest = new ArrayTest();
			aTest.findItem(ars, 1);
	}
}
